package top.xiaoqiannb.shapelessdao.procedures;

import top.xiaoqiannb.shapelessdao.network.ShapelessdaoModVariables;

import net.minecraft.world.level.GameType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.Entity;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.network.chat.Component;

public class DiyouxianoffProcedure {
	public static void execute(Entity entity) {
		if (entity == null)
			return;
		if ((entity.getCapability(ShapelessdaoModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ShapelessdaoModVariables.PlayerVariables())).gamemode_check == 0) {
			if (entity instanceof ServerPlayer _player)
				_player.setGameMode(GameType.SURVIVAL);
		}
		if ((entity.getCapability(ShapelessdaoModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ShapelessdaoModVariables.PlayerVariables())).gamemode_check == 1) {
			if (entity instanceof ServerPlayer _player)
				_player.setGameMode(GameType.CREATIVE);
		}
		if ((entity.getCapability(ShapelessdaoModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ShapelessdaoModVariables.PlayerVariables())).gamemode_check == 2) {
			if (entity instanceof ServerPlayer _player)
				_player.setGameMode(GameType.ADVENTURE);
		}
		if (entity instanceof Player _player && !_player.level().isClientSide())
			_player.displayClientMessage(Component.literal("\u6CD5\u672F\u5730\u884C\u4ED9\u65F6\u95F4\u7ED3\u675F"), false);
	}
}
